package com.banmao.algorithm.No101To200.No104;

public class Solution {

    private int max = 0;

    public int maxDepth(TreeNode root) {

        // 遍历树节点
        int tempDepth = 0;
        recursive(root, tempDepth);

        return max;
    }

    private void recursive(TreeNode root, int tempDepth) {
        if(root == null) {
            return;
        }

        tempDepth++;
        if(tempDepth > max) {
            max = tempDepth;
        }

        recursive(root.left, tempDepth);
        recursive(root.right, tempDepth);

    }

}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode() {
    }

    TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
